{include file="common/head"}
<div class="card">
    <div class="card-header">
        <div class="card-title">发送消息</div>
    </div>
    <div class="card-body">
        <div class="layui-form layui-form-pane" lay-filter="send">

            <div class="layui-form-item">
                <label class="layui-form-label">发送对象</label>
                <div class="layui-input-block">
                    <select lay-search="" name="user_id">
                        <option value="" selected>请搜索用户名称或选择全局发送</option>
                        <option value="0">全局发送</option>
                        {volist name="userList" id="user"}
                        <option value="{$user.id}">{$user.username}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <!-- <div class="layui-form-item">
                <label class="layui-form-label">发送模式</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="男" title="男" checked>
                    <input type="radio" name="sex" value="男" title="男" checked>
                </div>
            </div> -->
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">发送内容</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" name="msg"></textarea>
                </div>

            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-sm layui-bg-blue" lay-filter="submit" lay-submit>立即发送</button>
            </div>
        </div>
    </div>
</div>
{include file="common/bottom"}
<script>
    layui.use(function () {
        const layer = layui.layer
        const form = layui.form
        form.on('submit(submit)', function (data) {
            var field = data.field; // 获取表单全部字段值
            if(field.user_id == '') return layer.msg('请选择合适的发送对象')
            if(field.msg == '') return layer.msg('发送内容不能为空')
            $.post('/admin/msg/doSend', field, (res) => {
                if (res.code == 200) {
                    layer.msg('发送成功', { time: 1200 })
                } else {
                    layer.msg('发送失败')
                }
            })

            return false; // 阻止默认 form 跳转

        });
    })
</script>